package com.dingwen.treasure.business.component.listener;

import cn.hutool.core.convert.Convert;
import cn.hutool.json.JSONUtil;
import com.dingwen.treasure.business.component.event.CreateOrderEvent;
import com.dingwen.treasure.business.model.dto.OrderDto;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationListener;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;


/**
 *  物流监听器: 创建订单事件 --> 2: 物流业务逻辑实现 </br>
 *
 * @author dingwen
 * @date 2022/04/23
 */
@Component
@Order(0)
@Slf4j
public class LogisticsListener implements ApplicationListener<CreateOrderEvent> {
    /**
     * Handle an application event.
     *
     * @param event the event to respond to
     */
    @Override
    public void onApplicationEvent(CreateOrderEvent event) {
        // 订单事件对象DTO
        OrderDto orderDTO = Convert.convert(OrderDto.class,event.getSource());
        log.info("创建订单事件，物流业务逻辑执行，数据对象：\n{}", JSONUtil.toJsonPrettyStr(orderDTO));
    }
}
